package openapi

type PathSelection struct {
	Connect *OperationSelection `goblet:"connect" json:"connect,omitempty" yaml:"connect,omitempty"`
	Delete  *OperationSelection `goblet:"delete" json:"delete,omitempty" yaml:"delete,omitempty"`
	Get     *OperationSelection `goblet:"get" json:"get,omitempty" yaml:"get,omitempty"`
	Head    *OperationSelection `goblet:"head" json:"head,omitempty" yaml:"head,omitempty"`
	Options *OperationSelection `goblet:"options" json:"options,omitempty" yaml:"options,omitempty"`
	Patch   *OperationSelection `goblet:"patch" json:"patch,omitempty" yaml:"patch,omitempty"`
	Post    *OperationSelection `goblet:"post" json:"post,omitempty" yaml:"post,omitempty"`
	Put     *OperationSelection `goblet:"put" json:"put,omitempty" yaml:"put,omitempty"`
	Trace   *OperationSelection `goblet:"trace" json:"trace,omitempty" yaml:"trace,omitempty"`
}

func (p *PathSelection) GetByMethod(name string) *OperationSelection {
	switch name {
	case "get":
		return p.Get
	case "post":
		return p.Post
	case "options":
		return p.Options
	case "head":
		return p.Head
	case "delete":
		return p.Delete
	case "connect":
		return p.Connect
	case "patch":
		return p.Patch
	case "put":
		return p.Put
	case "trace":
		return p.Trace
	}
	return nil
}

func (p *PathSelection) AddByMethod(name string, selection ...*OperationSelection) *OperationSelection {
	var created *OperationSelection
	if len(selection) == 0 {
		created = new(OperationSelection)
	} else {
		created = selection[0]
	}
	switch name {
	case "get":
		p.Get = created
	case "post":
		p.Post = created
	case "options":
		p.Options = created
	case "head":
		p.Head = created
	case "delete":
		p.Delete = created
	case "connect":
		p.Connect = created
	case "patch":
		p.Patch = created
	case "put":
		p.Put = created
	case "trace":
		p.Trace = created
	default:
		return nil
	}
	return created
}
